{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Interfacing PowerModels.jl with pandapower"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "pandapower now has an interface to PowerModels.jl that can be used for efficient power system optimization.\n",
    "\n",
    "### What is PowerModels.jl and why should I use it?\n",
    "\n",
    "- [PowerModels.jl](https://lanl-ansi.github.io/PowerModels.jl/stable/) is  a package for steady-state power network optimization\n",
    "- It is based on the relatively new language [Julia](https://julialang.org/) which is gaining popularity in scientific applications\n",
    "- PowerModels uses Julia/JuMP for the optimization, which [clearly outperforms the Python alternative Pyomo](http://yetanothermathprogrammingconsultant.blogspot.com/2015/05/model-generation-in-julia.html)\n",
    "- PowerModels has a great modular design that allows you to define [different formulations for optimization problems](https://lanl-ansi.github.io/PowerModels.jl/stable/specifications/) based on different [network formulations](https://lanl-ansi.github.io/PowerModels.jl/stable/formulations/) as well as use several [relaxation schemes](https://lanl-ansi.github.io/PowerModels.jl/stable/relaxations/). You can then solve the problem using many open source as well as commercial solvers through [JuMP](http://www.juliaopt.org/JuMP.jl/0.18/installation.html#getting-solvers)\n",
    "\n",
    "### Well then why do I still need pandapower?\n",
    "\n",
    "Because pandapower:\n",
    "\n",
    "- allows you to easily define power systems with nameplate parameters and standard types\n",
    "- comes with thouroughly validated element models of transformers with tap changers, three-winding transformers, switches/breakers, extended ward equivalents and many more    \n",
    "- keeps all data in tables (pandas DataFrames), which makes data management and analysis very comfortable\n",
    "- provides different power system analysis functions, such as a (very fast) power flow, short-circuit calculation, state estimation, graph searches and a plotting library that can be used on the same grid models\n",
    "- allows you to do all pre- and postprocessing in Python, which still has a much richer environment of free libraries than Julia (currently 157,755 packages on PyPI vs. 1,906 libraries on Pkg)\n",
    "\n",
    "So using pandapower to define the grid models and then using PowerModels for the optimization really gives you the best of all worlds - you can use the rich environment of Python libraries, the sophisticated element models of pandapower, the modular optimization framework of PowerModels and the efficient mathematical modeling of JuMP."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Let's get started\n",
    "\n",
    "So here is an example of how it works. First, we create a grid in pandapower. Here, we create a meshed 110kV grid with four buses that is fed from an 220kV network through a 3-Winding transformer."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "This pandapower network includes the following parameter tables:\n",
       "   - bus (5 elements)\n",
       "   - load (3 elements)\n",
       "   - gen (3 elements)\n",
       "   - line (4 elements)\n",
       "   - trafo3w (1 element)\n",
       "   - poly_cost (3 elements)\n",
       "   - bus_geodata (5 elements)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandapower as pp\n",
    "import numpy as np\n",
    "net = pp.create_empty_network()\n",
    "\n",
    "min_vm_pu = 0.95\n",
    "max_vm_pu = 1.05\n",
    "\n",
    "#create buses\n",
    "bus1 = pp.create_bus(net, vn_kv=220., geodata=(5,9), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu)\n",
    "bus2 = pp.create_bus(net, vn_kv=110., geodata=(6,10), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu)\n",
    "bus3 = pp.create_bus(net, vn_kv=110., geodata=(10,9), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu)\n",
    "bus4 = pp.create_bus(net, vn_kv=110., geodata=(8,8), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu)\n",
    "bus5 = pp.create_bus(net, vn_kv=110., geodata=(6,8), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu)\n",
    "\n",
    "#create 220/110/110 kV 3W-transformer\n",
    "pp.create_transformer3w_from_parameters(net, bus1, bus2, bus5, vn_hv_kv=220, vn_mv_kv=110,\n",
    "                                        vn_lv_kv=110, vk_hv_percent=10., vk_mv_percent=10.,\n",
    "                                        vk_lv_percent=10., vkr_hv_percent=0.5,\n",
    "                                        vkr_mv_percent=0.5, vkr_lv_percent=0.5, pfe_kw=10,\n",
    "                                        i0_percent=0.1, shift_mv_degree=0, shift_lv_degree=0,\n",
    "                                        sn_hv_mva=100, sn_mv_mva=50, sn_lv_mva=50)\n",
    "\n",
    "#create 110 kV lines\n",
    "l1 = pp.create_line(net, bus2, bus3, length_km=70., std_type='149-AL1/24-ST1A 110.0')\n",
    "l2 = pp.create_line(net, bus3, bus4, length_km=50., std_type='149-AL1/24-ST1A 110.0')\n",
    "l3 = pp.create_line(net, bus4, bus2, length_km=40., std_type='149-AL1/24-ST1A 110.0')\n",
    "l4 = pp.create_line(net, bus4, bus5, length_km=30., std_type='149-AL1/24-ST1A 110.0')\n",
    "\n",
    "#create loads\n",
    "pp.create_load(net, bus2, p_mw=60)\n",
    "pp.create_load(net, bus3, p_mw=70)\n",
    "pp.create_load(net, bus4, p_mw=10)\n",
    "\n",
    "#create generators\n",
    "g1 = pp.create_gen(net, bus1, p_mw=40, min_p_mw=0, max_p_mw=200, vm_pu=1.01, slack=True)\n",
    "pp.create_poly_cost(net, g1, 'gen', cp1_eur_per_mw=1)\n",
    "\n",
    "g2 = pp.create_gen(net, bus3, p_mw=40, min_p_mw=0, max_p_mw=200, vm_pu=1.01)\n",
    "pp.create_poly_cost(net, g2, 'gen', cp1_eur_per_mw=3)\n",
    "\n",
    "g3 = pp.create_gen(net, bus4, p_mw=50, min_p_mw=0, max_p_mw=200, vm_pu=1.01)\n",
    "pp.create_poly_cost(net, g3, 'gen', cp1_eur_per_mw=3)\n",
    "net"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that PowerModels does not have a 3W-transformer model, but since pandapower includes the equations to calculates the equivalent branches for the 3W-transformers, it is possible to optimize grids with 3W-transformers in PowerModels through the pandapower interface. The same is true for other complex transformer models, switches/breaker, extended ward equivalents etc.\n",
    "\n",
    "Let's have a look at the grid we created with pandapowers plotting module:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0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fvvtNx09elR169b1yXUcDodatWqlnTt3auDAgWrVqpXy8vIUGxuruLg4Va1aVUlJSWrVqpXPToedTqdq1aqlnJwcHThwQFdffbVProPgwiPuACC48Ng8c+46mID+P3v27NF1112n2NhYHTx4ULVr1/bp9VJTU7Vu3TotX77csnnFzp079e2338put8tut2vLli3Ky8sr9+eio6OVlJSk5ORkJScn67bbblObNm1KttoVsXv3bl133XWqW7eujhw5YslrIjQQ0QAQvAjq8vEcaA9MnjxZTqdTDz30kM/jWSr+m7Ju3TrZ7fYKBfT58+e1aNEipaWlac2aNZd8/brrrtOBAweUn5+vRx55RImJicrPz5fD4VBOTo42b96s7du3a+vWrdq6das++eQTSVKrVq00atQoPfLIIxV6hJ/rExdTUlKI5wjDnAMAgheTj4ohoFU8dXA9qWLUqFF+uabrI669PeE/ePCgpkyZoqlTp+rIkSOSpISEBPXo0UPt2rVTcnKy2rRpoxo1auj555/XxIkTFRMTozfeeOOS1zp79qw2b96sjIwM2e12LVu2TJs3b9YTTzyh5557Tn/84x81cuRINW/e3Pg+Xe+vIh9ZjtBFRANAaCCozTDhkDRr1iwNGjRIbdu2VUZGhl9OSnfs2KHmzZvr6quv1oEDBzz+OYfDoVdffVUTJ05UYWGhJCkpKUmjRo3SH/7whzI/avw///mPmjZtqtjYWB06dEi1atVye428vDzNnz9faWlp2rBhQ8lfHzRokN577z3VrFnT4/vt0qWLVq9erUWLFql3794e/xzCC3MOAAhtkTj5YANdjl69emnJkiVKT0/X8OHD/XLNoqIi1ahRQ6dPn9bOnTs9+ojr//7v/9Zjjz2m7du3y2azqV+/fho9erRSU1PLjf577rlHq1at0ieffKI//vGPHt9nZmamPvroI82cOVMOh0MNGjRQenq6evbsWe7PnjlzRg0aNNDp06f5BUIQ0QAQRiIhqN11cGi/M4u4/su58847/XbNqKgo9e3bV5KUnp7u9nsdDodeeOEFtW/fXtu3b9cNN9yg9evXa+7cuerYsaNHJ+au92b6B6LWrVsrPT1dW7Zs0e23367Dhw+rV69eGjRokH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mQUNygM2YUN6lPON1ITk529+VyFRU5nVu3Op3ffON07thRoZfymXnz5jlDAtI4AAAamElEQVQlObt16xaQ6999991OSc533nnnkq8tX77cGR8f75Tk7Nq1q3P//v1eXyc3N9dps9mcMTExTofDUZFbdubk5DgHDx7slOS02WzOjz766JLvWbZsmVOSMzEx0VlQUFCh6yGy7dmzxzlhwgTn7t27A30rAAA/ysvLc3733XfOiRMnOufNm+c8evSo2+/fsaO4ObduLW7QinLXwT75JMJQsmfPHjVp0kR16tTR0aNH/fo0jp07d6pZs2aKj4/XoUOHVLOMp3yvW7dOffr0UXZ2tqpVq6Z33nlHQ4YMMb7PdevWKTU1VW3atNHGjRu9vuevvvpKw4YN06FDh1S5cmVNnz5djzzyyCXfV1hYqKZNm2rPnj1aunSpevTo4fU1AT6xEAAiR35+vn766Sd9//33SkxMVGpqqurWrev3+3DXwT6ZcISSxMRE1axZU8ePH9fBgwf9eu3JkydLkgYMGFBmPEvSHXfcoW3btql3797Kzc3V448/ru7du+vAgQNG13LNN1yTFVMnT57UkCFD1L17dx06dEi33nqrMjMzy4xnSYqOji6Zd6SlpXl1TcCFOQcAhD93U41gE/EBbbPZSjbB3333nd+u63Q6NXv2bEnSyHJ+PbR+/fpauHChZs+erZo1a2rFihVq2bKlXnnlFY+jf/369ZLMAzonJ0fvvvuuWrZsqRkzZqhy5cqaMGGCvvvuO914441uf3bIkCGKjY3VV199xS8TosKIaAAIT6EUzi4RH9CSdN9990mSPv74Y79dc9++fTp+/Lhq167tUdTabDYNHDhQ27dvLzmNHjdunBITE9W3b1+tXr36sk/rOHbsmL788ktFRUXp3nvv9ej+7Ha7hg4dqoYNG2rMmDEXnTo/99xzio4u/4NwateurXbt2snpdAbslzQRXohoAAgfoRjOLgS0pEGDBqlKlSpavXq1duzY4ZdrXjipMNkzu06j16xZowcffFA2m00LFixQly5d1Lx5c73yyitasmSJDh8+XPIzH3/8sc6fP6/77rtP1157bZmvm52dra+//lrjx4/XLbfcopSUFE2fPl3nzp1T165dtXDhQo9OnUsL9FNOEH6IaAAIbaEczi7uP0A8QtSoUUMDBw7U1KlTNXnyZL333ns+v2ZFHilns9nUsWNHdezYUYcPH9a0adOUnp6un3/+WePGjSv5vgYNGqht27Zat26dJKlx48aaNWuW8vPz5XA4dPLkSWVmZsput18SIjVq1NCQIUM0YsSIkk9r9Ibr/RHQsJIrovnFQgAIHaV/OXDQoEEhFc0XivincLhkZmaqTZs2ql69ug4dOqSEhASfXq9r1676+uuvtWDBAt1///0Vfr2CggItX75c69atk91ul91uV25ursc/Hx8fr9atWys5OVnt27dXnz59VOVyn4ZjYPv27WrRooUaNWqkffv2Vfj1gAvxdA4ACH7B8lQNU+46mIC+wO23364NGzYoLS2t3F/sqwin06natWsrOztb+/btU6NGjSy/RlFRkX755Rc98MAD2rZtm26//XY1a9ZMeXl5io2NVVxcnBISEtSiRQslJyerefPmqlTJ+n8hUVhYqOrVq+vMmTMlm2/ASkQ0AASnUA1nF3cdzITjAs8884w2bNig//qv/1KfPn3UoEEDn1wnJydH2dnZuuKKK3TNNdf45BpRUVHKyMjQtm3bVK1aNS1evFhXXnmlT67lTnR0tJo3b66MjAzt2rWLgIblmHMAQHAJp6nG5fBLhBfo37+/7r33XuXk5OiJJ5647FMtKurcuXOSpKpVq/rsg1uOHDmip556SlLxx2wHIp5dqlatKun39w1YjV8sBIDAC4dfDvQUAX0Bm82mKVOmqHr16lqyZEnJc5qt5nA4JBXvjn3B6XRq5MiRys7O1j333KMhQ4b45Dqecr1P1/sGfIGIBoDAiKRwdiGgS7n66qv17rvvSpKefvppZWVlWX6NgoICSfLoWcremDNnjhYtWqRq1app6tSpfv148rK4ttWu9w34ChENAP4TieHsQkCXYfDgwerevbtOnjypQYMGKS8vz9LXj4uLkyTLX1eSfv75Zz355JOSiqcbvtpYm3CdPLveN+BLRDQA+FYkh7MLAV0G15SjTp06Wr16tR599FEVFhZa9vqukLR6E7x//37dfffdysnJUc+ePQM+3XBxvU8CGv5CRAOA9Qjn3xHQl9G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0nSvn371LBhwwDfEXCpvXv3at68eerXr58aN24c6NsBAJ/Iz8/XTz/9pO+//16JiYlKTU0lmj3groMJaIudPXtWn3/+uVasWKGMjAzt3r3b+DViYmJ00003KSUlRY888ojuuOOOoPlQFE+9+uqr+utf/6q+fftq/vz5gb4d4LKIaADhinCuGAI6gHJycrRx40bZ7XZt3LhRx48fl8Ph0Llz5xQdHS1JysjIUFRUlN566y3dddddatmypWJjYwN8597Lz89X48aNlZWVpX//+9+68847A31LgFtENIBwQjhbw10HM0z1sZo1a6pz587q3LnzZb/ngQce0MKFC2W32/Xss8/68e58480331RWVpaSkpLUqVOnQN8OUC7XJpqIBhDKSofzoEGDCGcf4QQ6COzevVs33XSTzpw5oy+++EIPPPBAoG/Ja5mZmWrXrp0KCgq0Zs0adezYMdC3BHiMk2gAoYgTZ99w18E8hSMINGnSRG+99Zak4idznDhxIsB35J38/HwNHjxYBQUFevLJJ4lnhByezgEglPBUjcAhoIPEyJEj1alTJx07dkxPPfVUoG/HK2+++aY2b96sJk2aaPz48YG+HcArRDSAYEc4Bx4TjiBy4ZRj9uzZGjhwYKBvyWPff/+9UlNTmW4gbDDnABBsmGr4FxOOENGkSRNNnDhRkvTYY49pxYoVAb4jz2zdulU9evRQQUGBnn76aeIZYYGTaADBghPn4ENAB5kRI0Zo7NixOn/+vB544AGtXbs20Lfk1s6dO9W1a1fl5OSoT58+evvttwN9S4BliGgAgUQ4By8COsjYbDZNnDhRQ4cO1blz59StWzctX7480LdVpk2bNqlDhw46cuSI7rrrLs2ZM4eP7EbYIaIB+BvhHPwI6CBks9mUnp6u4cOHy+FwqHfv3poyZYrczNX97quvvlKnTp10/Phxde3aVYsXL1ZcXFygbwvwCSIagD8QzqGDgA5S0dHRmjx5sp577jkVFBToiSeeUPfu3XXw4MGA3tepU6c0dOhQde/eXbm5uerbt68WL16shISEgN4X4GtENABfIZxDDwEdxGw2m9566y3NmjVLNWvW1IoVK9SyZUvNmDEjIKfRrutPnz5dlStX1ltvvaXP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ACAAQIaAAAAMEBAAwAAAAYIaAAAAMAAAQ0AAAAYIKABAAAAAwQ0AAAAYICABgAAAAwQ0AAAAIABAhoAAAAwQEADAAAABghoAAAAwAABDQAAABggoAEAAAADBDQAAABggIAGAAAADBDQAAAAgAGb0+l0Xu6LtWvXVmJioh9vBwAAAAi8vXv36sSJE2V+zW1AAwAAALgYEw4AAADAAAENAAAAGCCgAQAAAAMENAAAAGCAgAYAAAAM/H+FAIyP+Db/wwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 720x576 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0xaebf630>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandapower.plotting as plot\n",
    "%matplotlib inline\n",
    "plot.simple_plot(net)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now lets run an OPF through PowerModels and look at the results (Note that the first time the runpm function is called, Julia is started in the background, which may take some time):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "pp.runpm_ac_opf(net)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Since Generator 1 has the lowest cost, all required power is supplied through this generator:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>va_degree</th>\n",
       "      <th>vm_pu</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>144.851017</td>\n",
       "      <td>11.037217</td>\n",
       "      <td>7.117490e-27</td>\n",
       "      <td>1.050000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>6.055925</td>\n",
       "      <td>-1.680643e+01</td>\n",
       "      <td>1.013179</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>13.126070</td>\n",
       "      <td>-1.298596e+01</td>\n",
       "      <td>1.040498</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         p_mw     q_mvar     va_degree     vm_pu\n",
       "0  144.851017  11.037217  7.117490e-27  1.050000\n",
       "1    0.000000   6.055925 -1.680643e+01  1.013179\n",
       "2    0.000000  13.126070 -1.298596e+01  1.040498"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.res_gen"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This however leeds to an overload in the three-winding transformer, through which g1 is connected:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    190.835372\n",
       "Name: loading_percent, dtype: float64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.res_trafo3w.loading_percent"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's set some constraints for the 3W-transformer and the lines and rerun the OPF:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "net.trafo3w[\"max_loading_percent\"] = 50\n",
    "net.line[\"max_loading_percent\"] = 20\n",
    "pp.runpm_ac_opf(net)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The constraints are complied with for all lines and the 3W transformer:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    49.97477\n",
       "Name: loading_percent, dtype: float64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.res_trafo3w.loading_percent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    19.047619\n",
       "1    12.295418\n",
       "2    19.207577\n",
       "3     7.088595\n",
       "Name: loading_percent, dtype: float64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.res_line.loading_percent"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The power is now generated by a mixture of the generators:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>va_degree</th>\n",
       "      <th>vm_pu</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>24.531626</td>\n",
       "      <td>-6.267018</td>\n",
       "      <td>2.961294e-28</td>\n",
       "      <td>1.031058</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>98.101643</td>\n",
       "      <td>-7.928705</td>\n",
       "      <td>-3.576364e-01</td>\n",
       "      <td>1.050000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>18.054898</td>\n",
       "      <td>9.928328</td>\n",
       "      <td>-1.446870e+00</td>\n",
       "      <td>1.048757</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        p_mw    q_mvar     va_degree     vm_pu\n",
       "0  24.531626 -6.267018  2.961294e-28  1.031058\n",
       "1  98.101643 -7.928705 -3.576364e-01  1.050000\n",
       "2  18.054898  9.928328 -1.446870e+00  1.048757"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.res_gen"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Accessing the full functionality of PowerModels.jl"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Apart from the AC OPF used in the example above, pandapower also has an interface to run the DC OPF:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>vm_pu</th>\n",
       "      <th>va_degree</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>lam_p</th>\n",
       "      <th>lam_q</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-23.521837</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.0</td>\n",
       "      <td>-2.783612</td>\n",
       "      <td>60.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.195199</td>\n",
       "      <td>-29.310098</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.0</td>\n",
       "      <td>-1.159257</td>\n",
       "      <td>-7.168065</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.0</td>\n",
       "      <td>-1.264625</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   vm_pu  va_degree       p_mw  q_mvar  lam_p  lam_q\n",
       "0    1.0   0.000000 -23.521837     NaN    0.0    0.0\n",
       "1    1.0  -2.783612  60.000000     0.0    0.0    0.0\n",
       "2    1.0   0.195199 -29.310098     NaN    0.0    0.0\n",
       "3    1.0  -1.159257  -7.168065     NaN    0.0    0.0\n",
       "4    1.0  -1.264625   0.000000     0.0    0.0    0.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.runpm_dc_opf(net)\n",
    "net.res_bus"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The julia file that is used to do that can be found in pandapower/pandapower/opf/run_powermodels_dc.jl and looks like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "using PowerModels\n",
    "using Ipopt\n",
    "using PP2PM\n",
    "\n",
    "function run_powermodels(json_path)\n",
    "    pm = PP2PM.load_pm_from_json(json_path)\n",
    "    result = PowerModels.run_dc_opf(pm, Ipopt.IpoptSolver(),\n",
    "                                    setting = Dict(\"output\" => Dict(\"branch_flows\" => true)))\n",
    "    return result\n",
    "end\n",
    "\"\"\";"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Of  course PowerModels is a great modular tool that allows you to do much more than that. You might want to use a different OPF formulation, a relaxation method or a different solver. You might even want to use one of the variants of PowerModels that are being developed, such as [PowerModelsACDC.jl](https://github.com/hakanergun/PowerModelsACDC.jl) or [PowerModelsReliability.jl](https://github.com/frederikgeth/PowerModelsReliability.jl).\n",
    "\n",
    "To do that, you can switch out the standard file with your own custom .jl file. Lets say we want to run a power flow instead of an OPF. There is a custom julia file for that in pandapower/tutorials/run_powermodels_custom.jl that looks like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "using PowerModels\n",
    "using Ipopt\n",
    "import JSON\n",
    "\n",
    "function run_powermodels(json_path)\n",
    "    pm = PP2PM.load_pm_from_json(json_path)\n",
    "    result = PowerModels.run_pf(pm, ACPPowerModel, Ipopt.IpoptSolver(),\n",
    "                                    setting = Dict(\"output\" => Dict(\"branch_flows\" => true)))\n",
    "    return result\n",
    "end\n",
    "\"\"\";"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We point the runpm function to this file, and as we can see by the flat voltage values, the OPF is now run with a DC network formulation:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>vm_pu</th>\n",
       "      <th>va_degree</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>lam_p</th>\n",
       "      <th>lam_q</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.010000</td>\n",
       "      <td>-6.034381e-36</td>\n",
       "      <td>-51.203353</td>\n",
       "      <td>-1.245026</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.004756</td>\n",
       "      <td>-5.426418e+00</td>\n",
       "      <td>60.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.010000</td>\n",
       "      <td>-6.495320e+00</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>-15.224075</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.010000</td>\n",
       "      <td>-3.621699e+00</td>\n",
       "      <td>-40.000000</td>\n",
       "      <td>16.142383</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.010243</td>\n",
       "      <td>-3.216964e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      vm_pu     va_degree       p_mw     q_mvar  lam_p  lam_q\n",
       "0  1.010000 -6.034381e-36 -51.203353  -1.245026    0.0    0.0\n",
       "1  1.004756 -5.426418e+00  60.000000   0.000000    0.0    0.0\n",
       "2  1.010000 -6.495320e+00  30.000000 -15.224075    0.0    0.0\n",
       "3  1.010000 -3.621699e+00 -40.000000  16.142383    0.0    0.0\n",
       "4  1.010243 -3.216964e+00   0.000000   0.000000    0.0    0.0"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.runpm(net, julia_file=\"run_powermodels_custom.jl\")\n",
    "net.res_bus"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The PowerModels data structure that was passed to Julia can be accessed like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'1': {'index': 1,\n",
       "  'bus_i': 1,\n",
       "  'zone': 1,\n",
       "  'bus_type': 3,\n",
       "  'vmax': 1.05,\n",
       "  'vmin': 0.95,\n",
       "  'va': 0.0,\n",
       "  'vm': 1.01,\n",
       "  'base_kv': 220.0},\n",
       " '2': {'index': 2,\n",
       "  'bus_i': 2,\n",
       "  'zone': 1,\n",
       "  'bus_type': 1,\n",
       "  'vmax': 1.05,\n",
       "  'vmin': 0.95,\n",
       "  'va': 0.0,\n",
       "  'vm': 1.0,\n",
       "  'base_kv': 110.0},\n",
       " '3': {'index': 3,\n",
       "  'bus_i': 3,\n",
       "  'zone': 1,\n",
       "  'bus_type': 2,\n",
       "  'vmax': 1.05,\n",
       "  'vmin': 0.95,\n",
       "  'va': 0.0,\n",
       "  'vm': 1.01,\n",
       "  'base_kv': 110.0},\n",
       " '4': {'index': 4,\n",
       "  'bus_i': 4,\n",
       "  'zone': 1,\n",
       "  'bus_type': 2,\n",
       "  'vmax': 1.05,\n",
       "  'vmin': 0.95,\n",
       "  'va': 0.0,\n",
       "  'vm': 1.01,\n",
       "  'base_kv': 110.0},\n",
       " '5': {'index': 5,\n",
       "  'bus_i': 5,\n",
       "  'zone': 1,\n",
       "  'bus_type': 1,\n",
       "  'vmax': 1.05,\n",
       "  'vmin': 0.95,\n",
       "  'va': 0.0,\n",
       "  'vm': 1.0,\n",
       "  'base_kv': 110.0},\n",
       " '6': {'index': 6,\n",
       "  'bus_i': 6,\n",
       "  'zone': 1,\n",
       "  'bus_type': 1,\n",
       "  'vmax': 1.05,\n",
       "  'vmin': 0.95,\n",
       "  'va': 0.0,\n",
       "  'vm': 1.0,\n",
       "  'base_kv': 220.0}}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net._pm[\"bus\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There is also a callback that allows you to add additional data to the PowerModels data structure in case it is not already added by the pandapower/PowerModels interface. In the callback you can add any data from the net, ppc or any source:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "foo\n",
      "50.0\n"
     ]
    }
   ],
   "source": [
    "def add_data(net, ppc, pm):\n",
    "    pm[\"gen\"][\"1\"][\"bar\"] = \"foo\"\n",
    "    pm[\"f_hz\"] = net.f_hz    \n",
    "\n",
    "pp.runpm(net, julia_file=\"run_powermodels_custom.jl\", pp_to_pm_callback=add_data)\n",
    "print(net._pm[\"gen\"][\"1\"][\"bar\"])\n",
    "print(net._pm[\"f_hz\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "These variables can now also be accessed on the Julia side, in case you need some more variables for custom optimizations.\n",
    "\n",
    "Keep in mind that indices in PowerModels are 1-based so that the indices are shifted by one between ppc and pm. Furthermore, the net might contain some elements that are not in the ppc, as they are out of service or disconnected, which is why the indices of all elements have to be identified through the lookup tables in `net._pd2ppc_lookups`.\n",
    "\n",
    "Some notes on the internal data structure can be found in [internal_datastructure.ipynb](internal_datastructure.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Timings"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Comparing the runopp function (that runs an OPF through PYPOWER) and the runpm function shows that PowerModels is much more performant:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.22 s ± 14.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "%timeit pp.runopp(net)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "221 ms ± 7.18 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "%timeit pp.runpm_ac_opf(net)"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
